//
//  BYSelectionDetails.m
//  FangXinLang
//
//  Created by AJY on 16/9/18.
//  Copyright © 2016年 AJY. All rights reserved.
//

#import "BYSelectionDetails.h"
#import "BYSelectionView.h"
#import "TitleModel.h"
#import "FirstList.h"
#define view_addWith 5
#define view_width ([UIScreen mainScreen].bounds.size.width-20*5)/4
@implementation BYSelectionDetails

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self makeMainContent];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

//保存选中的标题模型
-(NSMutableArray *)arrname{
    if (_arrname == nil) {
        _arrF = [NSMutableArray array];
        _arrname=[NSMutableArray array];
        _arrurl=[NSMutableArray array];
        NSArray *arr=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"First List.plist" ofType:nil]];
        for (NSDictionary *dic in arr) {
            FirstList *model=[FirstList firstlistWith:dic];
            [self.arrF addObject:model];
            [self.arrname addObject:model.name];
            [self.arrurl addObject:model.url];
            
        }
        
    }
    return _arrname;
}
-(NSMutableArray *)arrnameM{
    if (_arrnameM == nil) {
        _arrtitle = [NSMutableArray array];
        _arrnameM=[NSMutableArray array];
        _arrurlM=[NSMutableArray array];
        NSArray *arr=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"addbtn.plist" ofType:nil]];
        for (NSDictionary *dic in arr) {
            TitleModel *model=[TitleModel titlemodelWith:dic];
            [self.arrtitle addObject:model];
            [self.arrnameM addObject:model.name];
            [self.arrurlM addObject:model.url];
            
        }
        
    }
    return _arrnameM;
}

-(NSMutableArray *)views1
{
    if (_views1 == nil) {
        _views1 = [NSMutableArray array];
    }
    return _views1;
}

-(NSMutableArray *)views2
{
    if (_views2 == nil) {
        _views2 = [NSMutableArray array];
    }
    return _views2;
}

-(void)makeMainContent
{
    
    
   //    //点击添加频道的label和他的背景色添加分割视图
    UIView *bg_view = [[UIView alloc] initWithFrame:CGRectMake(0,30+45*((self.arrname.count -1)/4+1),[UIScreen mainScreen].bounds.size.width, 30)];
    bg_view.backgroundColor = [UIColor redColor];
    UILabel *morevalue_label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 100, 30)];
    morevalue_label.text = @"点击添加频道";
    morevalue_label.font = [UIFont systemFontOfSize:14];
    [bg_view addSubview:morevalue_label];
    [self addSubview:bg_view];
    
    //九宫格添加按钮
    NSInteger num = self.arrname.count;
    for (int i =0; i <num; i++) {
        
        BYSelectionView *view = [[BYSelectionView alloc] init];
        view.frame = CGRectMake(20+(20+view_width)*(i%4), 30+45*(i/4), view_width, 25);
        //添加标题
        
        [view makeSelectionViewWithTitle:self.arrname[i]];
        [self.views1 addObject:view];
        view.tag = 1;

        view.views_array=self.views1;
        view.views1=self.views1;
        view.views2=self.views2;
        [view setMoreChanelslabel:bg_view];
        [self addSubview:view];
    }
    
    //下边点btn
    NSArray *otherValues =self.arrnameM;
    NSInteger num2 = otherValues.count;
    for (int i=0; i<num2; i++) {
        BYSelectionView *view = [[BYSelectionView alloc] initWithFrame:CGRectMake(20+(20+view_width)*(i%4),CGRectGetMaxY(bg_view.frame)+20+45*(i/4), view_width, 25)];
        [view makeSelectionViewWithTitle:self.arrnameM[i]];
        [view setMoreChanelslabel:bg_view];
        [self.views2 addObject:view];
        view.tag = 0;
        view.views_array=self.views2;
        view.views1=self.views1;
        view.views2=self.views2;

        [self addSubview:view];
    }
    
    //偏移
    self.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, CGRectGetMaxY(bg_view.frame)+20+45*((num2-1)/4+1) + 50);

}
@end
